package libase.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author aspr0
 */
@Entity
@Table (name = "LEASE")
@XmlRootElement
@NamedQueries (
        {
    @NamedQuery (name = "Lease.findAll", query = "SELECT l FROM Lease l ORDER BY l.id"),
    @NamedQuery (name = "Lease.findById", query = "SELECT l FROM Lease l WHERE l.id = :id"),
    @NamedQuery (name = "Lease.findByLeaseDt", query = "SELECT l FROM Lease l WHERE l.leaseDt = :leaseDt"),
    @NamedQuery (name = "Lease.findByReturnDt", query = "SELECT l FROM Lease l WHERE l.returnDt = :returnDt"),
    @NamedQuery (name = "Lease.findByCompleted", query = "SELECT l FROM Lease l WHERE l.completed = :completed"),
    @NamedQuery (name = "Lease.findByExemplar", query = "SELECT l FROM Lease l WHERE l.exemplar = :exemplar"),
    @NamedQuery (name = "Lease.findByBook",
            query = "select l from Book b, in (b.exemplars) e, in (e.leases) l where b = :book"),
    @NamedQuery (name = "Lease.findCompletedByBook",
            query = "select l from Book b, in (b.exemplars) e, in (e.leases) l where b = :book and l.completed = 'Y'"),
    @NamedQuery (name = "Lease.findUncompletedByBook",
            query = "select l from Book b, in (b.exemplars) e, in (e.leases) l where b = :book and l.completed = 'N' "),
    @NamedQuery (name = "Lease.countByExemplar", query = "SELECT COUNT(l) FROM Lease l WHERE l.exemplar = :exemplar"),
})
public class Lease implements Serializable
{
    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @SequenceGenerator (allocationSize = 1, name = "slg", sequenceName = "SEQ_LEASE")
    @GeneratedValue (strategy = GenerationType.SEQUENCE, generator = "slg")
    @Id
    @Basic (optional = false)
    @NotNull
    @Column (name = "ID")
    private BigDecimal id;
    @Basic (optional = false)
    @NotNull
    @Column (name = "LEASE_DT")
    @Temporal (TemporalType.DATE)
    private Date leaseDt;
    @Column (name = "RETURN_DT")
    @Temporal (TemporalType.DATE)
    private Date returnDt;
    @Basic (optional = false)
    @NotNull
    @Size (min = 1, max = 20)
    @Column (name = "COMPLETED")
    private String completed;
    @JoinColumn (name = "READER_ID", referencedColumnName = "ID")
    @ManyToOne (optional = false)
    private Reader reader;
    @JoinColumn (name = "EXEMPLAR_ID", referencedColumnName = "ID")
    @ManyToOne (optional = false)
    private Exemplar exemplar;

    public Lease()
    {
    }

    public Lease(BigDecimal id)
    {
        this.id = id;
    }

    public Lease(BigDecimal id, Date leaseDt, String completed)
    {
        this.id = id;
        this.leaseDt = leaseDt;
        this.completed = completed;
    }

    public BigDecimal getId()
    {
        return id;
    }

    public void setId(BigDecimal id)
    {
        this.id = id;
    }

    public Date getLeaseDt()
    {
        return leaseDt;
    }

    public void setLeaseDt(Date leaseDt)
    {
        this.leaseDt = leaseDt;
    }

    public Date getReturnDt()
    {
        return returnDt;
    }

    public void setReturnDt(Date returnDt)
    {
        this.returnDt = returnDt;
    }

    public String getCompleted()
    {
        return completed;
    }

    public void setCompleted(String completed)
    {
        this.completed = completed;
    }

    public Reader getReader()
    {
        return reader;
    }

    public void setReader(Reader reader)
    {
        this.reader = reader;
    }

    public Exemplar getExemplar()
    {
        return exemplar;
    }

    public void setExemplar(Exemplar exemplar)
    {
        this.exemplar = exemplar;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Lease))
        {
            return false;
        }
        Lease other = (Lease) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "libase.entity.Lease[ id=" + id + " ]";
    }
}
